﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExamAnalysis.Model;
using System.Web.Security;
using ExamAnalysis.Core;
using ExamAnalysis.Core.Statistics;

namespace ExamAnalysis.Reports
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRoles();
                BindReport();
            }
        }
        protected void BindRoles()
        {
            string[] roles = Roles.GetRolesForUser();
            if (User.IsInRole("admin"))
                CurrentRole.Items.Add(new ListItem("超级管理员", "admin"));
            if (User.IsInRole("school"))
                CurrentRole.Items.Add(new ListItem("学校领导", "school"));
            if (User.IsInRole("grade"))
                CurrentRole.Items.Add(new ListItem("年级组长", "grade"));
            if (User.IsInRole("course"))
                CurrentRole.Items.Add(new ListItem("教研组长", "course"));
            if (User.IsInRole("class"))
                CurrentRole.Items.Add(new ListItem("班主任", "class"));
            if (User.IsInRole("teacher"))
                CurrentRole.Items.Add(new ListItem("任课老师", "teacher"));
            if (User.IsInRole("student"))
                CurrentRole.Items.Add(new ListItem("普通学生", "student"));
        }

        protected void BindReport()
        {
            List<ValueTextEntity> MicroItems = new List<ValueTextEntity>();
            List<ValueTextEntity> MacroItems = new List<ValueTextEntity>();
            List<ValueTextEntity> CompareItems = new List<ValueTextEntity>();
            
            string role=CurrentRole.SelectedValue;
           
            //总分
            MacroItems.AddRange(Core.Menu.GetReportList(role, Core.Menu.ReportType.MacroReports));
            //对比
            CompareItems.AddRange(Core.Menu.GetReportList(role, Core.Menu.ReportType.CompareReports));
            //小分
            MicroItems.AddRange(Core.Menu.GetReportList(role, Core.Menu.ReportType.MicroReports));

            //处理空白
            if (MacroItems.Count==0)
                MacroItems.Add(new ValueTextEntity("暂无", "#"));
            if (MicroItems.Count == 0)
                MicroItems.Add(new ValueTextEntity("暂无", "#"));
            if (CompareItems.Count == 0)
                CompareItems.Add(new ValueTextEntity("暂无", "#"));

            MacroRepeater.DataSource = MacroItems;
            MacroRepeater.DataBind();
            MicroRepeater.DataSource = MicroItems;
            MicroRepeater.DataBind();
            CompareRepeater.DataSource = CompareItems;
            CompareRepeater.DataBind();
        }

        protected void CurrentRole_Changed(object sender, EventArgs e)
        {
            BindReport();
        }
    }
}